package com.ymttest.database.sharding.config;

import com.alibaba.druid.pool.DruidDataSource;

public class DataSourceUtils {

	public static DruidDataSource initDataSource() {

		DruidDataSource dataSource = new DruidDataSource();
		dataSource.setInitialSize(Integer
				.valueOf(DataSourceSettingEnum.initialSize.getValue()));
		dataSource.setMinIdle(Integer.valueOf(DataSourceSettingEnum.minIdle
				.getValue()));
		dataSource.setMaxActive(Integer.valueOf(DataSourceSettingEnum.maxActive
				.getValue()));

		dataSource.setTimeBetweenConnectErrorMillis(Integer
				.valueOf(DataSourceSettingEnum.timeBetweenEvictionRunsMillis
						.getValue()));
		dataSource.setMinEvictableIdleTimeMillis(Integer
				.valueOf(DataSourceSettingEnum.minEvictableIdleTimeMillis
						.getValue()));
		dataSource.setValidationQuery(DataSourceSettingEnum.validationQuery
				.getValue());
		dataSource.setTestWhileIdle(Boolean
				.valueOf(DataSourceSettingEnum.testWhileIdle.getValue()));
		dataSource.setTestOnBorrow(Boolean
				.valueOf(DataSourceSettingEnum.testOnBorrow.getValue()));
		dataSource.setDefaultAutoCommit(false);

		dataSource.setQueryTimeout(Integer
				.valueOf(DataSourceSettingEnum.queryTimeout.getValue()));
		dataSource.setTransactionQueryTimeout(Integer
				.valueOf(DataSourceSettingEnum.queryTimeout.getValue()));
		return dataSource;
	}
}
